package tp.pr2;

/**
 * This class contains the information parsed from the input. It represents an
 * instruction that can be interpreted by the robot. An instruction encapsulates
 * an Action and possibly a Rotation (if the action is TURN) and/or an
 * identifiers (if the action needs an item)
 */
public class Instruction {
	private Action action;
	private Rotation rotation;
	private String id;

	/**
	 * Constructor por defecto.
	 */
	public Instruction() {
		action = Action.UNKNOWN;
		rotation = Rotation.UNKNOWN;
		this.id = null;
	}

	/**
	 * Crea una instruccion solo con el parametro action
	 * 
	 */
	public Instruction(Action action) {
		this.action = action;
		rotation = Rotation.UNKNOWN;
		this.id = null;
	}

	/**
	 * Crea una instruccion especificando sus dos parametros
	 */
	public Instruction(Action action, Rotation rotation) {
		this.action = action;
		this.rotation = rotation;
		this.id = null;
	}

	/**
	 * Creates an instruction with the action and the identifier for the
	 * instruction. It corresponds to instructions OPERATE, SCAN and PICK. The
	 * rotation is UNKNOWN
	 * 
	 * @param action
	 *            Action instruction
	 * @param id
	 *            - Identifier for the instruction
	 */
	public Instruction(Action action, java.lang.String id) {
		this.action = action;
		this.rotation = Rotation.UNKNOWN;
		this.id = id;
	}

	/**
	 * Checks if the instruction is a valid instruction
	 * 
	 * @return false if the action is UNKNOWN, the action is TURN but the
	 *         rotation is UNKNOWN or if an item identifier is mandatory for the
	 *         given action but it does not contain an item identifier. Return
	 *         true otherwise
	 * 
	 */
	public boolean isValid() {
		boolean ret = true;
		if ((action.equals(Action.UNKNOWN) || (action.equals(Action.UNKNOWN) && (rotation
				.equals(Rotation.UNKNOWN))))
				|| action.equals(Action.TURN)
				&& rotation.equals(Rotation.UNKNOWN)
				|| (action.equals(Action.PICK) || action.equals(Action.OPERATE))
				&& this.id == null)
			ret = false;

		return ret;

	}

	/**
	 * Getter del atributo action
	 */
	public Action getAction() {
		return action;
	}

	/**
	 * Getter del atributo rotation
	 */
	public Rotation getRotation() {
		return rotation;
	}

	/**
	 * Getter del atributo id
	 */
	public java.lang.String getId() {
		return id;
	}

}
